package org.testmyapp.entities;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

import org.testmyapp.persistence.BusinessObjectMarker;

@Entity
@IdClass(InsuredPersonPk.class)
public class InsuredPerson extends AbsProcessRelatedObject implements
		BusinessObjectMarker {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5283401309944897776L;

	public static String tableName = "InsuredPerson";

	@Id
	@ManyToOne
	@JoinColumn(name = "contract_id_fk")
	private Contract contract;
	@Id
	@OneToOne
	@JoinColumn(name = "person_id_fk")
	private Person person;

	public Contract getContract() {
		return contract;
	}

	public void setContract(Contract contract) {
		this.contract = contract;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public String toString() {
		return "VP: Vertrag " + contract.getId() + ", Person: "
				+ person.toString();
	}

	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (!(o instanceof InsuredPerson) || o == null)
			return false;
		InsuredPerson other = (InsuredPerson) o;
		if ((this.getContract() == null && other.getContract() != null)
				|| (!this.getContract().equals(other.getContract()))) {
			return false;
		}
		if ((this.getPerson() == null && other.getPerson() != null)
				|| !this.getPerson().equals(other.getPerson())) {
			return false;
		}
		return true;
	}

}
